<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <title>生态圈系统-优惠券列表</title>
  <link rel="icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">
  <link rel="shortcut icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">

  <!-- CSS  -->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link href="plugins/bootstrap-4.0.0/css/bootstrap.min.css" th:href="@{/plugins/bootstrap-4.0.0/css/bootstrap.min.css}" type="text/css" rel="stylesheet"/>
  <link href="css/materialize.css" th:href="@{/css/materialize.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="plugins/perfect-scrollbar/perfect-scrollbar.css" th:href="@{/plugins/perfect-scrollbar/perfect-scrollbar.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="plugins/bootstrap-datepicker/css/bootstrap-datepicker.css" th:href="@{/plugins/bootstrap-datepicker/css/bootstrap-datepicker.css}" type="text/css" rel="stylesheet"/>
  <link href="plugins/bootstrap-sweetalert/sweetalert.css" th:href="@{/plugins/bootstrap-sweetalert/sweetalert.css}" type="text/css" rel="stylesheet"/>
  <link href="css/style.css" th:href="@{/css/style.css}" type="text/css" rel="stylesheet"/>
</head>
<body>
  <header>
    <nav class="" role="navigation" style="background-color: #f4f6f9;">
      <div class="nav-wrapper">
        <ul class="right hide-on-med-and-down">
          <!-- 
          <li><a class="blue-text waves-effect dropdown-trigger" href="#!" data-target="dropdown1" style="vertical-align: top;"><span th:if="${session.user!=null}" th:text="${session.user.username}">admin</span><i class="material-icons right">arrow_drop_down</i></a></li>
           -->
          <li><a class="grey-text waves-effect dropdown-trigger" href="#!" data-target="dropdown1" style="vertical-align: top;"><span sec:authentication="name">admin</span><i class="material-icons right">arrow_drop_down</i></a></li>
          <ul id="dropdown1" class="dropdown-content">
            <li><a href="#modal3" class="waves-effect grey-text modal-trigger">修改密码</a></li>
            <li><a th:href="@{/admin/logout}" class="waves-effect grey-text">退出登录</a></li>
          </ul>
        </ul>

        <a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
      </div>
    </nav>
  </header>

  <div th:replace="common/aside_admin :: aside"></div>

  <main class="" style="height: calc(100% - 48px); background-color: #f4f6f9;">
    <div class="row">
      <h6 style="margin: 0 0 0 15px;" id="page-title" active-menu="coupon-list-menu">优惠券列表</h6>
    </div>

    <div class="row white" style="margin: 0 15px; height: inherit;">
      

      <div class="col s12" style="height: inherit;"> <!-- Note that "m8 l9" was added -->
        <div class="">
          <form id="search">
            <div class="row" style="margin-bottom: 0;">
              <div class="input-field col s2 blue-text">
                <select name="activityId">
                  <option value="" selected>全部</option>
                  <option th:each="a : ${activities}" th:value="${a.id}"  th:text="${a.title}" th:selected="${a.id} == ${search.activity.id}"></option>
                </select>
                <label>权益</label>
              </div>
			        <div class="input-field col s2">
			          <input type="text" name="customerNumber" id="customer_id" th:value="${search.customer.customerNumber}">
                <label for="customer_id">客户号</label>
			        </div>
			        <div class="input-field col s2 blue-text">
                <select name="status">
                  <option value="" selected>全部</option>
                  <option value="VALID" th:selected="${search.status == T(com.yumo.kangchenjunga.coupon.Status).VALID}">未使用</option>
                  <option value="USED" th:selected="${search.status == T(com.yumo.kangchenjunga.coupon.Status).USED}">已使用</option>
                  <option value="IGNORED" th:selected="${search.status == T(com.yumo.kangchenjunga.coupon.Status).IGNORED}">已回收</option>
                </select>
                <label>状态</label>
              </div>
              <div class="input-field col s2">
                <input type="text" name="effectiveTime" id="effectiveTime" class="date-picker" th:value="${search.effectiveTime}">
                <label for="effectiveTime">开始日期</label>
              </div>
              <div class="input-field col s2">
                <input type="text" name="expirationTime" id="expirationTime" class="date-picker" th:value="${search.expirationTime}">
                <label for="expirationTime">结束日期</label>
              </div>
              <div class="input-field col s1">
                <a th:href="'javascript:search();'" class="waves-effect waves-light btn-floating search-btn"><i class="material-icons right">search</i></a>
              </div>
              <div class="input-field col s1" style="padding-right: 0;">
                <a class="waves-effect waves-light right" href="javascript:;" style="top: 0.5rem; color: rgba(0, 0, 0, 0.54);"><i class="material-icons" style="position: relative; top: 0.5rem; color: rgba(0, 0, 0, 0.54);">file_download</i>下载模板</a>
              </div>
              <div class="input-field col s6">
                <a class="waves-effect waves-light btn light-blue darken-1 right white-text modal-trigger" href="#modal1" style="margin-right: 30px;"><i class="material-icons right"></i>导入优惠券</a>
              </div>
            </div>
          </form>
        </div>

        <div style="padding-top: 0; height: inherit;">
          
          <div>
            <table>
              <thead>
                <tr>
                  <th width="20%">权益</th>
                  <th width="20%">客户号</th>
                  <th width="20%">验证码</th>
                  <th width="10%">状态</th>
                  <th width="15%">开始日期</th>
                  <th width="15%">结束日期</th>
                </tr>
              </thead>
            </table>
          </div>

          <div id="table_body_div" style="height: calc(100% - 88px); position: relative;">
            <div>
	            <table class="highlight">
	              <thead>
	                <tr>
	                  <th class="no-padding" width="20%"></th>
	                  <th class="no-padding" width="20%"></th>
	                  <th class="no-padding" width="20%"></th>
	                  <th class="no-padding" width="10%"></th>
	                  <th class="no-padding" width="15%"></th>
	                  <th class="no-padding" width="15%"></th>
	                </tr>
	              </thead>
	              <tbody>
	                <tr th:each="c : ${coupons}">
	                  <td th:text="${c.activity.title}" th:title="${c.activity.title}">中秋大闸蟹</td>
	                  <td th:text="${c.customer.customerNumber}" th:title="${c.customer.customerNumber}">99元包邮</td>
	                  <td th:text="${c.couponCode}" th:title="${c.couponCode}"></td>
	                  <td th:switch="${c.status}" th:case="${T(com.yumo.kangchenjunga.coupon.Status).VALID}" title="未使用">未使用</td>
	                  <td th:switch="${c.status}" th:case="${T(com.yumo.kangchenjunga.coupon.Status).USED}" title="已使用">已使用</td>
	                  <td th:switch="${c.status}" th:case="${T(com.yumo.kangchenjunga.coupon.Status).IGNORED}" title="已回收">已回收</td>
	                  <td th:text="${c.effectiveTime}" th:title="${c.effectiveTime}">2018-09-01</td>
	                  <td th:text="${c.expirationTime}" th:title="${c.expirationTime}">2018-09-30</td>
	                </tr>
	              </tbody>
	            </table>
            </div>
          </div>
          <ul class="pagination">
            <!-- <li class="disabled"><a href="#!"><i class="material-icons">chevron_left</i></a></li>
            <li class="active"><a href="#!">1</a></li>
            <li class="waves-effect"><a href="#!">2</a></li>
            <li class="waves-effect"><a href="#!">3</a></li>
            <li class="waves-effect"><a href="#!">4</a></li>
            <li class="waves-effect"><a href="#!">5</a></li>
            <li class="waves-effect"><a href="#!"><i class="material-icons">chevron_right</i></a></li> -->
          </ul>

        </div>

      </div>

  	</div>
  </main>  

  <!-- <footer class="white page-footer teal">
    <div class="footer-copyright">
      <div class="black-text container">
      Made by <a class="brown-text text-lighten-3" href="http://materializecss.com">Materialize</a>
      </div>
    </div>
  </footer> -->
  
  <!-- Modal Structure -->

  <div id="modal1" class="modal modal-fixed-footer" style="width: 500px; height: 400px;">
    <div class="modal-header">
      <h6>选择文件</h6>
      <a class="btn-flat modal-close"><i class="material-icons">close</i></a>
    </div>
    <div class="modal-content" style="border: unset; border-radius: 0;">
      <div class="row" style="width: 100%;">
        <form id="uploadForm" class="col s12">
          <div class="row">
            <div class="col s8 file-field input-field">
				      <div class="btn">
				        <span>File</span>
				        <input type="file" name="file">
				      </div>
				      <div class="file-path-wrapper">
				        <input class="file-path validate" type="text">
				      </div>
				    </div>
          </div>
          <input type="reset" style="display:none;" />
        </form>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-light btn-flat" style="margin-right: 10px;">取消</a>
      <button class="btn waves-effect waves-light light-blue darken-1" type="submit" name="action" style="margin-right: 10px;" onclick="upload()">确认</button>
    </div>
  </div>
  
  <div th:replace="common/update_pwd :: #modal3"></div>

  <!--  Scripts-->
  <script src="js/jquery-3.3.1.min.js" th:src="@{/js/jquery-3.3.1.min.js}"></script>
  <script src="js/materialize.js" th:src="@{/js/materialize.js}"></script>
  <script src="plugins/perfect-scrollbar/perfect-scrollbar.min.js" th:src="@{/plugins/perfect-scrollbar/perfect-scrollbar.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" th:src="@{/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" th:src="@{/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js}" charset="UTF-8"></script>
  <script src="plugins/bootstrap-sweetalert/sweetalert.min.js" th:src="@{/plugins/bootstrap-sweetalert/sweetalert.min.js}"></script>
  <script src="js/common.js" th:src="@{/js/common.js}"></script>
  <script src="js/jquery.page.js" th:src="@{/js/jquery.page.js}"></script>
  <script th:inline="javascript">
    $(".pagination").createPage({
      pageCount: [[${coupons.totalPages}]],
      current: [[${coupons.number}]] + 1,
      backFn:function(p){
        window.location.href = "coupons?page=" + (p - 1) + "&" + formParamsSerialize($("#search").find('input, select'));
      }
    });
    
    function search() {
      console.log($("#search").serialize());
      window.location.href = "coupons?" + formParamsSerialize($("#search").find('input, select'));
    }
    
    function upload() {
    	var form = new FormData(document.getElementById("uploadForm"));
      $.ajax({
        url: "/kangchenjunga/api/v1/upload",
        data: form,
        processData: false,
        contentType: false,
        type: "POST",
        success: function(data, textStatus) {
          console.log(data);
          swal({
            title: "",
            text: "上传成功!",
            icon: "success",
            //timer: 2000,
          });
          window.location.reload();
          $("#modal1 input[type=reset]").trigger("click");
          $('#modal1').modal('close');
        },
        error: function (data, textStatus, errorThrown) {
          //console.log(data);
          swal({
            title: "",
            text: "上传失败!",
            icon: "error",
            //timer: 2000,
          });
          M.updateTextFields();
        }
      });

    }
  </script>
  </body>
</html>
